package com.rd.student.ruanjian.class3.gaochenxi.LianXi3.NumberFour;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class NumberFourTwo {
   public static void main(String[] args) {
      //想用线程池按照顺序打印
      ExecutorService service = Executors.newSingleThreadExecutor();
      int[] num = {1};
      for (int i = 0; i < 10; i++) {
         service.execute(new Runnable() {
            @Override
            public void run() {
               if (num[0] <= 10) {
                  System.out.print("第" + num[0] + "人已通过山洞，");
                  num[0]++;
                  if (num[0] <= 10) {
                     System.out.println("正在召唤第" + num[0] + "个人");
                  } else {
                     System.out.println();
                     System.out.println("所有人已通过山洞");
                  }
                  try {
                     Thread.sleep(1000);
                  } catch (InterruptedException e) {
                     throw new RuntimeException(e);
                  }
               }
            }
         });
      }
      service.shutdown();
   }
}
